package com.example;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.security.spec.RSAOtherPrimeInfo;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

/**
 * 向tb_brand表中添加一条数据
 */

public class AddTest {
    @Test
    public void addTest() throws  Exception{
        Properties prop=new Properties();
        prop.load(new FileInputStream("注解开发控制bean生命周期/druid.properties"));
        DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
        Connection conn = dataSource.getConnection();
        String brand_name="周黑鸭";
        String company_name="周黑鸭有限公司";
        int ordered=1;
        String description="周黑鸭很好吃";
        Integer status=1;

        String sql="insert into tb_brand (brand_name,company_name,ordered,description,status) values(?,?,?,?,?)";

        PreparedStatement pstmt = conn.prepareStatement(sql);

        pstmt.setString(1,brand_name);
        pstmt.setString(2,company_name);
        pstmt.setInt(3,ordered);
        pstmt.setString(4,description);
        pstmt.setInt(5,status);

        int i = pstmt.executeUpdate();
        if (i>0){
            System.out.println("添加成功");

        }else{
            System.out.println("添加失败");
        }

        pstmt.close();
        conn.close();

    }
}
